<template>
  <el-dialog :title="title" :visible="visible" append-to-body @close="close">
    <el-form
      ref="form"
      :model="entityData"
      :rules="rules"
      label-width="80px"
      label-position="right"
      style="width:90%;margin:0px auto;"
    >
      <!--表单区域 -->
      <el-form-item label="标题" prop="title">
        <el-input v-model="entityData.title" :readonly="readonly" />
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <!--<tinymce v-model="entityData.content" :image-upload-params="options.query" :height="800" />-->
        <tinymce
          :key="+new Date()"
          v-model="entityData.content"
          :height="800"
          :readonly="readonly"
          :image-upload-params="imageStore"
        />
      </el-form-item>
      <el-form-item label="是否重要" prop="importantFlag">
        <dictionary-radio-group
          v-model="entityData.importantFlag"
          :readonly="readonly"
          :code="constant.DICTIONARY_TYPE_CODES.YES_OR_NO"
        />
      </el-form-item>
      <el-form-item label="是否置顶" prop="topFlag">
        <dictionary-radio-group
          v-model="entityData.topFlag"
          :readonly="readonly"
          :code="constant.DICTIONARY_TYPE_CODES.YES_OR_NO"
        />
      </el-form-item>
      <el-form-item label="允许评论" prop="commentFlag">
        <dictionary-radio-group
          v-model="entityData.commentFlag"
          :readonly="readonly"
          :code="constant.DICTIONARY_TYPE_CODES.YES_OR_NO"
        />
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <dictionary-radio-group
          v-model="entityData.status"
          :code="constant.DICTIONARY_TYPE_CODES.STATUS"
          :readonly="readonly"
        />
      </el-form-item>
      <el-form-item label="范围">
        <organization-multiple-select
          v-model="entityData.organizationIdList"
          @changeSelect="changeSelect"
        />
      </el-form-item>
      <el-form-item label="发布时间" prop="publishTime">
        <el-date-picker v-model="entityData.publishTime" type="date" class="form-item" readonly />
      </el-form-item>
      <el-form-item label="发布人" prop="publisher">
        <el-input v-model="entityData.publisher" readonly />
      </el-form-item>
      <el-form-item label="访问量" prop="readCount">
        <el-input v-model="entityData.readCount" readonly />
      </el-form-item>

      <el-form-item label="附件">
        <attachment-manager ref="attachmentViewer" :entity-id="entityData.id" />
      </el-form-item>
      <el-form-item>
        <attachment-uploader
          :entity-type="constant.ENTITY_TYPE_NOTICE"
          :entity-id="entityData.id"
          :module-code="constant.MODULE_TYPE.SUPPORT"
          :show-success-files="false"
          :server-url="'/support/attachment/upload'"
          @fileComplete="fileComplete"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button v-show="saveButtonVisible" type="primary" @click="save">保存</el-button>
      <el-button @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { detailMixin } from '@/mixin/detailMixin'
import Tinymce from '@/components/Tinymce'
import AttachmentUploader from '@/modules/support/view/attachment/AttachmentUploader'
import AttachmentManager from '@/modules/support/view/attachment/AttachmentManager'
const MODULE_CODE = 'support'
const ENTITY_TYPE = 'notice'
export default {
  name: ENTITY_TYPE + '-detail',
  components: { Tinymce, AttachmentUploader, AttachmentManager },
  mixins: [detailMixin],
  data() {
    return {
      entityType: ENTITY_TYPE,
      moduleCode: MODULE_CODE,
      // eslint-disable-next-line no-eval
      api: eval('this.$api.' + MODULE_CODE + '.' + ENTITY_TYPE),
      pageCode: MODULE_CODE + ':' + ENTITY_TYPE + ':',
      entityData: {

      },
      rules: {
        title: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请选择状态', trigger: 'blur' }
        ]
      },
      currentRow: {},
      imageStore: {
        entityType: ENTITY_TYPE,
        // 虚拟id，用于富文本上传的图片
        entityId: '0',
        moduleCode: MODULE_CODE
      }
    }
  },
  methods: {
    // 附件上传完成，刷新展示组件
    fileComplete() {
      this.$refs.attachmentViewer.list()
    },
    changeSelect(value) {
      this.entityData.organizationIdList = value
    }
  }

}
</script>

<style lang="scss">
</style>
